﻿// toast
$(function () {

    var user = getCookie('user');
    var org = getCookie('org');
    if (user == undefined || user == null || user == '') {
        //alert("请重新登陆！");
        $.alert("请重新登陆！", "未登录", function () {
            //return alert('回调');
            window.location.href = '../login.html';
        });
    } else {
        //alert('当前用户：' + user);
        $('#dqyd').text('当前门店：' + org);
    }

    //

    var XiaoShouDingji = getQuery('id');
    var selectdate = getQuery('selectdate');
    //XiaoShouDingji = '1';
    
    $.showLoading();
    var tm = setTimeout(function () {
        $.hideLoading();
        $.alert("系统繁忙，请稍后再试！", "超时", function () { });
    }, 20000);

    $.ajax({
        type: "GET",
        url: "http://" + B_Url + "/api/yudingfind",
        //数据，json字符串
        data: { info: 'getorderDetail', XiaoShouDingji: XiaoShouDingji, selectdate: selectdate},
        success: function (result) {
            $.hideLoading();
            clearTimeout(tm);
            if (result == undefined || result == null || result.YaoDianID == null || result.YuDingShu == null) {
                $.alert("错误订单！", "错误", function () {
                    return;
                });
            } else {
                savedate = selectdate;
                yaodian = result.YaoDianID;
                $('#birthday').val(formartDateInt(result.YuDingRiQi));
                $('#job').val(result.YaoDianMing);
                $('#js_input').val(result.XingMing);
                $('#js_input_sfz').val(result.ShenFenZheng);
                //$('#js_input_jtzz').val(result.ZhuZhi);
                $('#js_input_sl').val(result.YuDingShu);
                $('#js_input_dhhm').val(result.DianHuan);
               

                if (result.YuDingShu == result.XiaoShuLiang) {
                    $('#showTooltips').addClass('weui-btn_warn');
                    $('#showTooltips').text('订单已处理完成');
                } else {
                    //显示按钮
                    $('#showTooltips').removeClass('weui-btn_disabled');
                }
            }
        },
        error: function (e) { }
    });

    //保存预定信息
    $('#showTooltips').on('click', function () {

        $.confirm("确定订单后提交", "确认", function () {
            SendOrder(XiaoShouDingji);
            //$.toast("删除成功!");
        }, function () {
            //取消操作
        });
    });

});


//发送当前预定信息
var yaodian;
var savedate;
function SendOrder(XiaoShouDingji) {
    var ydm = $('#job').val();
    var ck_ydm = getCookie('org');
    if (ydm != ck_ydm) {
        $.alert("", '药店不一致，无法处理订单', function () {  
        });
        return;
    }
    

    $.showLoading();
    var tm = setTimeout(function () {
        $.hideLoading();
        $.alert("系统繁忙，请稍后再试！", "超时", function () { });
    }, 20000);

    $.ajax({
        type: "GET",
        url: "http://" + B_Url + "/api/yudingsave",
        //数据，json字符串
        data: { info: 'updateorder', XiaoShouDingji: XiaoShouDingji, selectdate: savedate},
        success: function (result) {
            $.hideLoading();
            clearTimeout(tm);
            if (result == undefined || result == null || result == -1) {
                $.alert("", "没到销售时间", function () {
                    return;
                });
            } else {
                var msg = "提交成功！";
                if (result == -5) {
                    msg = '不需要重复提交！';
                } else if (result == -2) {
                    msg = '库存不足！';
                } else if (result == -999) {
                    msg = '提交出错！';
                } else if (result == -444) {
                    msg = '过期订单，不能购买！';
                } else {
                    window.location.reload();
                }
                $.alert("", msg, function () {
                    return;
                });
                
            }
        },
        error: function (e) { }
    });


}



